package lobster.games.studios;

import lobster.games.studios.R;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.MotionEvent;

public class Splash extends Activity {

	// how long until we go to the next activity
	protected int _splashTime = 1500;
	protected int ACTIVITY_MAIN = 100;

	private Thread splashTread;

	/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		final Splash sPlashScreen = this;

		// thread for displaying the SplashScreen
		splashTread = new Thread() {
			@Override
			public void run() {
				try {
					synchronized (this) {
						// wait 1,5 sec
						wait(_splashTime);
					}

				} catch (InterruptedException e) {
				} finally {
					// start a new activity
					Intent i = new Intent();
					i.setClass(sPlashScreen, Main.class);
					startActivityForResult(i, ACTIVITY_MAIN);
					// stop();
				}
			}
		};
		splashTread.start();
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == ACTIVITY_MAIN) {
			if (resultCode == 0) {
				finish();
			}
		}
	}

	// Function that will handle the touch
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			synchronized (splashTread) {
				splashTread.notifyAll();
			}
		}
		return true;
	}

}
